package zhoufu.sz.sanxiao_check.ui.fragment;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import eu.davidea.flexibleadapter.FlexibleAdapter;
import eu.davidea.viewholders.FlexibleViewHolder;
import zhoufu.sz.sanxiao_check.R;
import zhoufu.sz.sanxiao_check.inject.HasComponent;
import zhoufu.sz.sanxiao_check.ui.BaseActivity;

/**
 * Created by hyc on 2016/6/18.
 */
public class BaseFragment extends StatedFragment
        implements DialogInterface.OnCancelListener, View.OnClickListener,FlexibleAdapter.OnItemClickListener
{

    public BaseActivity mAct;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        setHasOptionsMenu(true);
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    /**
     * Gets a component for dependency injection by its type.
     */
    @SuppressWarnings("unchecked")
    protected <C> C getComponent(Class<C> componentType)
    {
        return componentType.cast(( (HasComponent<C>) getActivity() ).getComponent());
    }

    protected void showSnackBar(View view, int resId)
    {
        Snackbar.make(view, resId, Snackbar.LENGTH_LONG).show();
    }

    @Override
    public void onAttach(Context context)
    {
        super.onAttach(context);
        mAct = (BaseActivity) context;
    }

    @Override
    public void onStart()
    {
        super.onStart();
    }


    @Override
    public void onStop()
    {
        super.onStop();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        super.onActivityResult(requestCode, resultCode, data);
        System.out.println("requestCode = " + requestCode);
    }

    ProgressDialog _progressDialog;

    protected void showProgreesDialog()
    {
        showProgreesDialog(true);
    }

    protected void showProgreesDialog(boolean cancelAble){
        if ( _progressDialog == null )
        {
            _progressDialog = ProgressDialog
                    .show(this.getContext(), getString(R.string.insprition), getString(
                            R.string.dialog_progress_message)
                            , true, cancelAble, this);
        }
        _progressDialog.show();
    }
    protected void hideProgreesDialog()
    {
        if ( _progressDialog != null )
        {
            _progressDialog.dismiss();
        }
    }

    @Override
    public void onCancel(DialogInterface dialogInterface)
    {

    }

    public BaseActivity getmAct()
    {
        return mAct;
    }


    private final String TAG = this.getClass().getSimpleName();


    @Override public void onClick(View v)
    {
        System.out.println("v.getId() = " + v.getId());
    }

    @Override
    public boolean onItemClick(int position) {

        return false;
    }

    @Override
    public boolean onItemClick(FlexibleViewHolder flexibleViewHolder, FlexibleAdapter adapter, int position) {
        return false;
    }

}
